{extend name='../app/admin/view/common/pop.html' /}

{block name="content"}
<form class="layui-form j-form" style="margin-top: 15px" id="form">

    <div class="layui-form-item">
        <label for="" class="layui-form-label">品牌名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="title" value="{$info.title}">
        </div>
        <div class="layui-input-block j-form-tips">
            请输入
        </div>
    </div>
    <div class="layui-form-item">
        <label for="" class="layui-form-label">LOGO</label>
        <div class="layui-input-block j-upload">
            <a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-sm j-upload-dom">
                <input type="file" name="logo" id="upload_1" class="j-file" onchange="upload_logo(event,this)"
                       accept="image/*" multiple="multiple">
                <input type="text" class="j-upload-input" readonly="" value="{$info.logo_path}">
                <input type="hidden" class="j-upload-input" readonly="" value="{$info.logo}" name="logofile">
                <i class="layui-icon layui-icon-upload"></i>选择文件</a>
        </div>
        <div class="j-img-preview-logo">
            {if $info.logo_path}
                <img src="{$info.logo_path}" alt="" class="j-img-preview-item">
            {/if}
        </div>

        <div class="layui-input-block j-form-tips">，双击可删除</div>
        <script>

            function upload_logo(event, e) {
                var files = event.target.files
                    , preview = document.querySelector('.j-img-preview-logo')
                    , reader = new FileReader();

                if (files) {
                    $.each(files, function (index, file) {
                        reader.addEventListener("load", function () {
                            var image = new Image();
                            image.title = file.name;
                            image.src = this.result;
                            image.classList.add('j-img-preview-item');
                            image.ondblclick = function (e) {
                                $(e.currentTarget).parent().prev().find('input[type=text]').val('')
                                $(e.currentTarget).parent().prev().find('input[type=hidden]').val('')
                                $(e.currentTarget).remove();

                            }
                            preview.append(image);
                        }, false);

                        reader.readAsDataURL(file);
                    })
                }

                $(e).next().val($(e).val())


            }

        </script>
    </div>
    <div class="layui-form-item">
        <label for="" class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="description" class="layui-textarea">{$info.description}</textarea>
        </div>
        <div class="layui-input-block j-form-tips">
            请输入
        </div>
    </div>
    <div class="layui-form-item">
        <label for="" class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" {if $info.status >0}checked{/if}>
        </div>
        <div class="layui-input-block j-form-tips">
            请输入
        </div>
    </div>
    <div class="layui-form-item">
        <label for="" class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" class="layui-input" name="sort" value="{$info.sort}">
        </div>
        <div class="layui-input-block j-form-tips">
            请输入
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-form-label"></div>
        <div class="layui-input-inline">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="create">提交</button>
        </div>
    </div>
</form>
{/block}


{block name="script"}
<script>
    layui.use(['layer', 'form', 'jquery'], function () {
        var layer = layui.layer,
            form = layui.form,
            $ = layui.jquery;
        form.render();

        form.on('submit(create)', function (data) {
            var fd = new FormData(document.getElementById("form"));
            $.ajax({
                url: "{:plugin_url()}",
                type: 'post',
                processData: false,//必须
                contentType: false,//必须
                data: fd,
                success: function (r) {
                    layer.msg(r.msg);
                    if (r.code == 1) {
                        setTimeout(function () {
                            parent.location.reload();
                        }, 1000)
                    }
                },
                error: function (r) {
                    layer.msg(r.msg);
                }
            });
            return false;
        })
    })
</script>
{/block}